const Service = require("uni-cloud-router").Service;
module.exports = class UserService extends Service{
	async pmRecruitmentAdmin({data,type}){
		/**
		 * data：可变参数 | Object
		 * type：固定参数 | String | 状态：'add'（添加），'delete'（删除），'get'（获取），'update'（更改）
		 */
		let res,resData = {status:0,msg:"成功"};
		
		switch (type){
			case 'add':
				res = await this.db.collection('recruitment_info').add(data);
				break;
			case 'delete':
				res = await this.db.collection('recruitment_info').doc(data._id).remove();
				break;
			case 'get':
				res = await this.db.collection('recruitment_info').where(data).get();
				(res.affectedDocs !== 0 || res.data.length !== 0) ? resData.data = res.data : '';
				break;
			case 'update':
				res = await this.db.collection('recruitment_info').doc(data._id).update({status:0});
				break;
			default:
				break;
		}
		
		if(res.affectedDocs !== 0){
			return resData;
		} else {
			return {
				status:1,
				msg:"稍后重试"
			}
		}
		
		return {
			status:-1,
			msg:"稍后重试"
		}
	}
}